package generic;

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        CustomList<String> customList = new CustomList<>();
        customList.set("dd");
        System.out.println(customList.get());

        PhoneShop<IPhone> phonePhoneShop = new PhoneShop<>();
        phonePhoneShop.get(new IPhone());

        List<Apple> apples = new ArrayList<>();
        List<Banana> bananas = new ArrayList<>();
        List<TFruit> fruits = new ArrayList<>();
        getAllPrice(apples);
        getAllPrice(bananas);

        Apple apple = new Apple();
        setAllPrice(apples, apple);
        setAllPrice(fruits, apple);
    }

    // 必须是 TFruit 的子类才能进行操作
    public static void getAllPrice(List<? extends TFruit> fruits) {
        fruits.forEach(fruit -> System.out.println(fruit.getPrice()));
    }

    // Apple 基类都可以，只能能装 Apple 就行
    public static void setAllPrice(List<? super Apple> fruits, Apple apple) {
        System.out.println("xxx");
    }
}
